package com.kpx.app.wigdet;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.kpx.app.R;
import com.kpx.app.utils.uiutils.ToastUtil;

/**
 * 申请或拒绝退款理由Dialog
 *
 * @author SS
 */
public class DialogInputRefundReason extends BaseDialog implements View.OnClickListener {

    private EditText mInputRefundReasonView;
    private OnSendMessageOnClickListener onSendMessageOnClickListener;
    private String mHintAlertString;

    public DialogInputRefundReason(Context context, String hintAlertString, OnSendMessageOnClickListener onSendMessageOnClickListener) {
        super(context);
        mHintAlertString = hintAlertString;
        setOnSendMessageOnClickListener(onSendMessageOnClickListener);
        setContent();
    }

    private void setContent() {
        setContentView(R.layout.dialog_input_refund_reason_layout);
        findViewById(R.id.refund_reason_close_btn).setOnClickListener(this);
        mInputRefundReasonView = (EditText) findViewById(R.id.inputRefundReasonView);
        mInputRefundReasonView.setHint(mHintAlertString);
        findViewById(R.id.sendMessageBtn).setOnClickListener(this);
    }

    /**
     * 确定
     */
    public void setOnSendMessageOnClickListener(OnSendMessageOnClickListener listener) {
        this.onSendMessageOnClickListener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.refund_reason_close_btn:
                dismiss();
                break;
            case R.id.sendMessageBtn:
                if (null != onSendMessageOnClickListener) {
                    String refundReason = mInputRefundReasonView.getText().toString();
                    if (TextUtils.isEmpty(refundReason)) {
                        ToastUtil.getInstance().showToast(getContext(), mHintAlertString);
                        return;
                    }
                    onSendMessageOnClickListener.onSendMessageOnClick(this, refundReason);
                }
                break;
        }
    }

    public interface OnSendMessageOnClickListener {
        void onSendMessageOnClick(Dialog dialog, String refundReason);
    }
}
